using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.BasicsDatum;
using SmartWMS.Server.BasicsDatumServer.LocationServer;
using SmartWMS.Server.BasicsDatumServer.LocationServer.Dto;
using Yitter.IdGenerator;

namespace SmartWMS.API.Controllers.BasicsDatumMange
{
    /// <summary>
    /// 入库管理111
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "BasicsDatum")]
    public class ILocationsController : ControllerBase
    {
       private readonly ILocationServers _locationServers;
        public ILocationsController(ILocationServers locationServers)
        {
            _locationServers = locationServers;
        }

        /// <summary>
        /// 仓库下拉
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<Warehouse>> GetWarehousBoxAsync()
        {
            try
            {
                var list= await _locationServers.GetWarehousBoxAsync();
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 库位管理列表
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<List<LocationDtoPes>> GetLocationDtoPes(PaginationDto dto)
        {
            try
            {
                var list= _locationServers.GetLocationDtoPes(dto);
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
        
        /// <summary>
        /// 添加库位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddLocationAsync(LocationDtoPes dto)
        {
            try
            {
                // dto.LocationCode = YitIdHelper.NextId().ToString();
                dto.CreateTime = DateTime.Now;
                var resault = await _locationServers.AddLocationAsync(dto);
                return resault;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 反填库位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<LocationDtoPes> RackLocation(LocationDtoPes dto)
        {
            try
            {
                var list = _locationServers.RackLocation(dto);
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改库位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> UpdateLocationAsync(LocationDtoPes dto)
        {
            try
            {
                var list= await _locationServers.UpdateLocationAsync(dto);
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改库位状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> UpdateLocationIsDisable(LocationDtoPes dto)
        {
            try
            {
                var list= await _locationServers.UpdateLocationIsDisable(dto);
                return list;
                
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 库位删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeleteLocationIsDisable(LocationDtoPes dto)
        {
            try
            {
                //删除当前列表
                var result= await _locationServers.DeleteLocationIsDisable(dto);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 批量删除库位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<Response<bool>> DeletesLocationIsDisable(LocationDtoPes dto)
        {
            try
            {
                var result =  _locationServers.DeletesLocationIsDisable(dto);
                return result;

            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
